package com.qd.p2p.web.action;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;

import com.qdlc.p2p.common.util.HtmlParserTool;
import com.qdlc.p2p.common.util.htmlparser.LinkFiterImpl;
import com.qdlc.p2p.common.util.siteMapUtil;
import org.apache.struts2.convention.annotation.Action;

import com.qdlc.p2p.biz.service.SystemConfigService;
import com.qdlc.p2p.biz.web.action.BaseAction;

/**
 * 前台清理系统缓存
 * @author yinliang
 * @version 2.0
 * @Date   2014年12月24日
 */
@SuppressWarnings("rawtypes")
public class SystemCacheAction extends BaseAction{
	@Resource
	private SystemConfigService systemConfigService;
	
	@Action("/system/clean")
	public void clean() throws Exception {
		Map<String, String> map = new HashMap<String, String>();
		systemConfigService.clean();
		map.put("msg", "ok");
		printWebJson(map);
	}

	@Action("/link/clean")
	public void linkClean() throws Exception{
		Map<String, String> map = new HashMap<String, String>();
		systemConfigService.cleanLink();
		map.put("msg", "ok");
		printWebJson(map);
	}

	@Action("/siteMap/add")
	public void siteMap() throws Exception {
		Map<String, String> resultMap = new HashMap<String, String>();
		String path= request.getSession().getServletContext().getRealPath("/");
		Set<String> linkSet =  HtmlParserTool.extractLinks(null,"https://www.99jzg.com/",new LinkFiterImpl());
		Set<String> set = new HashSet<String>();
		for (String webUrl:linkSet) {
			set =   HtmlParserTool.extractLinks(set,webUrl,new LinkFiterImpl());
		}
		siteMapUtil.sitemapGenerator(set,path);
		resultMap.put("msg", "ok");
		printWebJson(resultMap);
	}

}
